package com.pentajock.docdb.types;

import java.util.*;

public class DepartmentProperties {
	public enum PropertyID {			// Datatypes returned from Property.get()
		PROPERTY_NAME,			// String
		IS_STATIC,			// Boolean
		LOCKED,				// Boolean
		STATIC_VALUE,			// String
		SHOW_IN_HEADER,			// Boolean
		POSITION_IN_HEADER,		// Integer
		SHOW_IN_PROPERTIES;		// Boolean
	}

	public class Property {
		private EnumMap<PropertyID, Object> propertyMap;
		private boolean locked;
		
		public Property() {
			propertyMap = new EnumMap<PropertyID, Object>(PropertyID.class);
			locked = false;
		}
		
		public Object get(PropertyID id) {
			return propertyMap.get(id);
		}
		
		public boolean set(PropertyID id, Object value) {
			if(!locked) {
				propertyMap.put(id, value);
				return true;
			}
			return false;
		}
		
		public String toString() {
			String result = new String();
			for(PropertyID id : PropertyID.values()) {
				result += id.name() + ":=" + get(id) + "\n";
			}
			result += "-----------------------\n";
			return result;
		}
		
		public void lock() {
			locked = true;
		}
	}
	
	private HashMap<String, DepartmentProperties.Property> properties;
	private boolean locked;
	
	public DepartmentProperties() {
		properties = new HashMap<String, DepartmentProperties.Property>();
		locked = false;
	}
	
	public Property getProperty(String propertyName) {
		return properties.get(propertyName);
	}
	
	public boolean setProperty(String propertyName, Property property) {
		if(!locked) {
			properties.put(propertyName, property);
			return true;
		}
		return false;
	}
	
	public Collection<String> getPropertyNames() {
		return properties.keySet();
	}
	
	public void lock() {
		locked = true;
	}
	
	public Property createNewProperty() {
		return new Property();
	}
}
